<?php

namespace app\admin\model;

use think\Model;


class VVideo extends Model
{
    // 表名
    protected $name = 'v_video';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'media_type_text',
        'creation_time_text',
        'update_time_text',
        'is_save_text'
    ];

    public function getMediaTypeList()
    {
        return ['1' => __('Media_type 1'), '2' => __('Media_type 2')];
    }

    public function getIsSaveList()
    {
        return ['0' => __('Is_save 0'), '1' => __('Is_save 1')];
    }


    public function getMediaTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['media_type']) ? $data['media_type'] : '');
        $list = $this->getMediaTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getCreateTimeAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }

    public function getCreationTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['creation_time']) ? $data['creation_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }


    public function getIsSaveTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_save']) ? $data['is_save'] : '');
        $list = $this->getIsSaveList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setCreationTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    static function getVideo($video_ids)
    {
        return self::where('id', 'in', $video_ids)->column('title', 'id');
    }
}
